<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>产品工序设计</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="Content-Type" content="multipart/form-data; charset=utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<link rel="stylesheet" href="../../../lib/layui-v2.5.5/css/layui.css" media="all">
		<link rel="stylesheet" href="../../../css/layuicmspublic.css" media="all">
		<link rel="stylesheet" href="../../../css/public.css" media="all">
		<link rel="stylesheet" href="../../../js/bootstrap/css/bootstrap.min.css" media="all">

		<!-- <link rel="stylesheet" type="text/css" href="https://raw.githack.com/hnzzmsf/layui-formSelects/master/dist/formSelects-v4.css" /> -->
	</head>

	<body>

		<!-- <div id="zzh"> -->
		<div class="layuimini-container">
			<div class="layuimini-main">
				<!--搜索开始-->
				<fieldset class="layui-elem-field layuimini-search">
					<legend>搜索信息</legend>
					<div style="margin: 10px 10px 10px 10px">
						<form class="layui-form layui-form-pane" action="" id="searchFrm">
							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">商品</label>
									<div class="layui-input-inline">
										<!--  商品id  -->
										<select name="providerid" class="providerSel">
											<option value="">请选择商品</option>
										</select>
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">商品名称</label>
									<div class="layui-input-inline">
										<input type="text" name="goodsname" autocomplete="off" class="layui-input">
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">生产批号</label>
									<div class="layui-input-inline">
										<input type="text" name="productcode" autocomplete="off" class="layui-input">
									</div>
								</div>
							</div>
					</div>
					<div class="layui-form-item">
						<div class="layui-block" style="text-align: center;">
							<a class="layui-btn " lay-submit="" lay-filter="data-search-btn"><label class="layui-icon layui-icon-search"></label>搜索</a>
							<a class="layui-btn layui-btn-warm" onclick="javascript:$('#searchFrm')[0].reset()" lay-filter="data-search-btn"><label
								 class="layui-icon layui-icon-refresh"></label>重置</a>
						</div>
					</div>
					</form>
			</div>
			</fieldset>

			<!--搜索结束-->
			<div id="zzh">
				<!--表格开始-->
				<table class="layui-hide" id="goodsTable" lay-filter="goodsTable"></table>

				<div style="display: none;" type="text/html" id="goodsToolBar">
					<a class="layui-btn goods_btn_add layui-btn-sm" lay-event="add">添加</a>
					<a class="layui-btn goods_btn_batchdelete layui-btn-sm layui-btn-danger data-count-delete" lay-event="batchdelete">批量删除</a>
				</div>
				<div style="display: none;" type="text/html" id="goodsTableBar">
					<a class="layui-btn goods_btn_update layui-btn-xs layui-btn-warm data-count-delete" lay-event="update">审核</a>
				</div>
				<!--  是否可用 选择  -->
				<!--表格结束-->

				<!--添加和修改的弹出层开始-->
				<div id="addOrUpdateDiv" style="display: none;padding: 1.3125rem 3.3125rem 0.3125rem 3.3125rem;">
					<form method="post" class="layui-form layui-form-pane" lay-filter="dataFrm" id="dataFrm">
						<div class="layui-col-md12 layui-col-xs12">
							<div class="layui-row layui-col-space10">
								<div class="layui-col-md12 layui-col-xs15">
									<div class="layui-form-item magt3">
										<label class="layui-form-label">设计单号：</label>
										<div class="layui-input-block">
											<input type="text" name="designId" disabled="disabled" class="layui-input" lay-verify="required" placeholder="设计单号">
										</div>
									</div>
									<div class="layui-form-item magt3">
										<label class="layui-form-label">产品名称：</label>
										<div class="layui-input-block">
											<!-- 做修改  -->
											<input type="text" name="productName" disabled="disabled" class="layui-input" lay-verify="required"
											 placeholder="产品名称">
										</div>
									</div>
									<div class="layui-form-item magt3">
										<label class="layui-form-label">产品设计人：</label>
										<div class="layui-input-block">
											<input type="text" name="designer" disabled="disabled" class="layui-input" lay-verify="required" placeholder="设计人">
										</div>
									</div>
									<div class="layui-form-item magt3">
										<label class="layui-form-label">产品编号：</label>
										<div class="layui-input-block">
											<input type="text" name="productId" disabled="disabled" class="layui-input" lay-verify="required"
											 placeholder="产品编号">
										</div>
									</div>
									<table class="layui-table">
										<thead>
											<tr style="background-color: #fff;">
												<th>序号</th>
												<th>工序名称</th>
												<th>描述</th>
												<th width="120px">工时</th>
												<th>单位工时成本</th>
												<th>工时成本小计</th>
											</tr>
										</thead>
										<tbody>
											<tr v-for="(item,index) in sel_brand_obj">
												<td>{{item.id}}</td>
												<td>{{item.procedureName}}</td>
												<td>{{item.procedureDescribe}}</td>
												<td>{{item.labourHourAmount}}</td>
												<td>{{item.costPrice}}</td>
												<td>{{item.subtotal}}</td>
												<!-- item.tile*item.cost == "NaN" == false ? 0   -->
											</tr>
										</tbody>
									</table>
									<div class="layui-form-item">
										<div class="layui-form-item layui-inline">
											<label class="layui-form-label">工序设计人：</label>
											<div class="layui-input-block">
												<input type="text" disabled="disabled" name="register" class="layui-input" lay-verify="required"
												 placeholder="工序设计人">
											</div>
										</div>
										<div class="layui-form-item layui-inline">
											<label class="layui-form-label">工时总计：</label>
											<div class="layui-input-block">
												<input type="text" disabled="disabled" name="costPriceSum" class="layui-input" lay-verify="required"
												 placeholder="工时总计">
											</div>
										</div>

										<!-- <div class="layui-form-item layui-inline">
											<label class="layui-form-label">日期：</label>
											<div class="layui-input-block">
												<input type="text" disabled="disabled" name="nowTime" class="layui-input" id="test1">
											</div>
										</div> -->
										<div class="layui-form-item layui-form-text">
											<label class="layui-form-label">描述：</label>
											<div class="layui-input-block" style="margin-top: -5px;">
												<textarea name="procedureDescribe" disabled="disabled" id="desc" placeholder="请输入内容" class="layui-textarea"></textarea>
											</div>
										</div>
									</div>
								</div>
							</div>

						</div>
						<div class="layui-form-item">
							<div class="" style="text-align: center;padding-top: 20px;">
								<a class="layui-btn" lay-submit="" lay-filter="doSubmit"><label class="layui-icon layui-icon-release"></label>审核通过</a>
								<a class="layui-btn layui-btn-warm" lay-submit="" lay-filter="doSubmit2" ><label class="layui-icon layui-icon-refresh"></label>审核不通过</a>
							</div>
						</div>
					</form>
				</div>
				<!--添加和修改的弹出层结束-->
				<input type="hidden" v-model="id" id="id" />
			</div>
		</div>
		<!-- </div> -->
		<!-- </div> -->
		<script src="../../../lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
		<script src="../../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
		<script src="../../../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
		<script src="../../../lib/jq-module/jquery.particleground.min.js" charset="utf-8"></script>
		<script src="../../../lib/common/jquery.cookie.min.js" charset="utf-8"></script>
		<script src="../../../lib/common/common.js" charset="utf-8"></script>
		<script src="../../../js/vue/vuejs-2.5.16.js" charset="utf-8"></script>
		<script src="../../../js/vue/vue-selected.js" charset="utf-8"></script>
		<script src="../../../js/vue/axios-0.18.0.js" charset="utf-8"></script>
		<script src="../../../js/vue/qs.js" charset="utf-8"></script>


		<script>
			layui.use(['form', 'table', 'laydate', 'layer', 'upload'], function() {
				var form = layui.form;
				var table = layui.table;
				var laydate = layui.laydate;
				var layer = layui.layer;
				var upload = layui.upload;
				//执行一个laydate实例
				laydate.render({
					elem: '#test1' //指定元素
				});

				// 加载商品下拉框信息
				$.get(api3 + "provider/getAllAvailableProvider", function(res) {
					// 获取下拉框
					var select_providerSel = $(".providerSel");
					var html = "<option value =''>请选择商品</option>";
					var data = res.data;
					$.each(data, function(index, item) {
						html += "<option value =" + item.id + ">" + item.providername + "</option>";
					});
					select_providerSel.html(html);
					// 重新初始化 下拉框 要不然 数据显示不出来
					form.render("select");
				});




				// 加载数据表格
				var tableIns = table.render({
					elem: '#goodsTable',
					url: api3 + 'ProductionProcessDesign/findNotAuditPage',
					// toolbar: "#goodsToolBar",
					cellMinWidth: true,
					height: 'full-220',
					cols: [
						[{
								type: "checkbox",
								fixed: "left"
							},
							{
								field: 'designId',
								title: '设计单编号',
								align: "center"
							},
							{
								field: 'productId',
								title: '产品编号',
								align: "center"
							},
							{
								field: 'productName',
								title: '产品名称',
								align: "center"
							},
							{
								field: 'register',
								title: '设计人',
								align: "center"
							},
							{
								field: 'registerTime',
								title: '登记时间',
								align: "center"
							},
							{
								field: 'costPriceSum',
								title: '工时总成本',
								align: "center"
							},
							{
								title: '操作',
								templet: '#goodsTableBar',
								fixed: "right",
								align: "center",
								width: 180
							}
						]
					],
					page: true
				});

				// 监听搜索操作
				form.on('submit(data-search-btn)', function(data) {
					var params = $("#searchFrm").serialize();
					//执行搜索重载
					table.reload('goodsTable', {
						page: {
							curr: 1
						},
						url: api3 + 'goods/loadAllGoods?' + params
					});
					return false;
				});

				//监听表头的事件
				table.on('toolbar(goodsTable)', function(obj) {
					var checkStatus = table.checkStatus(obj.config.id);
					switch (obj.event) {
						case 'batchdelete':
							batchdelete();
							break;
						case 'add':
							openAddGoods();
							break;
					};
				});

				//监听行数据的事件
				table.on('tool(goodsTable)', function(obj) {
					var data = obj.data;
					if (obj.event === 'delete') {
						layer.prompt({
							formType: 1,
							value: '',
							maxlength: 6, //可输入文本的最大长度，默认500
							title: '敏感操作，请输入口令'
						}, function(value, index, elem) {
							if (value == 'yby123') {
								$.post(api3 + "goods/deleteGoods", {
									id: data.id
								}, function(res) {
									layer.msg(res.msg);
									obj.del();
									layer.close(index);
								})
							} else {
								layer.msg("口令错误");
							}
						});

					} else if (obj.event === 'update') {
						openUpdateGoods(data);
					} else if (obj.event === 'show') {
						showGoods(data);
					} else if (obj.event === 'goodsimg') {
						layer.open({
							type: 1,
							title: "商品图片",
							closeBtn: false,
							area: '400px',
							shade: 0.8,
							id: 'LAY_layuipro_goodsimg' //设定一个id，防止重复弹出
								,
							btn: ['帅帅气气'],
							btnAlign: 'c',
							moveType: 1 //拖拽模式，0或者1
								,
							content: '<img class="layui-upload-img  layui-circle userFaceBtn userAvatar" style="width: 300px;height: 300px;margin: 0 40px;" src="' +
								baseUrl + data.goodsimg + '"  name="goodsimg">'

						});

					}
				});



				//监听可用操作
				form.on('switch(availableSwitch)', function(obj) {
					// $.get(api3+"goods/getGoodsByProviderId",{id: this.value},function(res){
					// });
					// var checkStatus = table.checkStatus('availableSwitch'); //idTest 即为基础参数 id 对应的值
					// var data = checkStatus.data;
					// var length = checkStatus.data.length;
					// console.log(data)
					$.post(api3 + "goods/updateGoods", {
						id: this.value,
						available: obj.elem.checked ? 1 : 0
					}, function(res) {
						layer.msg(res.msg);
						tableIns.reload();
					})
				});
				
				// 审核窗体
				function openUpdateGoods(data) {
					console.log(data)
					$('#id').val(data.id)
					$('#id')[0].dispatchEvent(new Event('input'));
					vm.loadSelBrandObj()
					mainIndex = layer.open({
						type: 1,
						title: '审核[' + data.productName + ']生产工序',
						content: $("#addOrUpdateDiv"),
						area: ['950px', '800px'],
						success: function(index) {
							// url = api3 + "goods/updateGoods";
							//装载数据表格
							form.val("dataFrm", data);
							if (data.goodsimg) {
								$(".thumbImg").attr("src", baseUrl + data.goodsimg);
							}
						}
					});
				}
				//审核成功
				form.on("submit(doSubmit)", function(data) {
					console.log(data)
					var btn = $(this);
					btn.text("提 交 中...").attr("disabled", "disabled").addClass("layui-disabled");
					var params = $("#dataFrm").serialize();
					axios.post(api3 + "ProductionProcessDesign/updateAuditStatus?id=" + $('#id').val() + "&status=S001-2", {}, {
							headers: {
								'token': token
							}
						})
						.then(function(response) {
							console.log(response.data)
							btn.text("审核通过").attr("disabled", "").removeClass("layui-disabled");
							tableIns.reload();
							layer.close(mainIndex);
						}).catch(function(reason) {
							console.log(reason);
						})
					
					// $.post(url, params, function(res) {
					// 	layer.msg(res.msg);
					// 	if (res.code == 200) {
					// 		btn.text("提交").attr("disabled", "").removeClass("layui-disabled");
					// 		tableIns.reload();
					// 	}
					// 	layer.close(mainIndex);
					// })
					return false;
				})
				//审核失败
				form.on("submit(doSubmit2)", function(data) {
					console.log(data)
					var btn = $(this);
					btn.text("提 交 中...").attr("disabled", "disabled").addClass("layui-disabled");
					var params = $("#dataFrm").serialize();
					axios.post(api3 + "ProductionProcessDesign/updateAuditStatus?id=" + $('#id').val() + "&status=S001-3", {}, {
							headers: {
								'token': token
							}
						})
						.then(function(response) {
							console.log(response.data)
							btn.text("审核不通过").attr("disabled", "").removeClass("layui-disabled");
							tableIns.reload();
							layer.close(mainIndex);
						}).catch(function(reason) {
							console.log(reason);
						})
					
					// $.post(url, params, function(res) {
					// 	layer.msg(res.msg);
					// 	if (res.code == 200) {
					// 		btn.text("提交").attr("disabled", "").removeClass("layui-disabled");
					// 		tableIns.reload();
					// 	}
					// 	layer.close(mainIndex);
					// })
					return false;
				})
			});
		</script>
		<script type="text/javascript">
			Vue.component('v-select', VueSelect.VueSelect);
			var vm = new Vue({
				el: '#zzh',
				data: {
					sel_brand_obj: [],
					id: 0
				},
				methods: {
					loadSelBrandObj: function() {
						var _this = this
						axios.post(api3 + "ProductionProcessDesign/findPppDetailsById?id=" + this.id, {}, {
								headers: {
									'token': token
								}
							})
							.then(function(response) {
								// alert("Sdsdsd")
								console.log(response.data)
								_this.sel_brand_obj = response.data;
							}).catch(function(reason) {
								console.log(reason);
							})
					}
					
				},
				mounted() {
					// this.loadSelBrandObj()
				}
			})
		</script>
		<!-- <script src="https://unpkg.com/jquery@3.4.1/dist/jquery.js" type="text/javascript" charset="utf-8"></script>
	 
	<script src="https://raw.githack.com/hnzzmsf/layui-formSelects/master/dist/formSelects-v4.min.js" type="text/javascript" charset="utf-8"></script>
	 
	<script type="text/javascript">
	    //加载模块
	    layui.use(['jquery', 'formSelects'], function () {
	        var formSelects = layui.formSelects;
	   });
	</script> -->

	</body>

</html>
